//
//  TicketListViewController.m
//  MINFOBBS
//
//  Created by 蔡龙生 on 13-11-26.
//  Copyright (c) 2013年 minfo. All rights reserved.
//

#import "TicketListViewController.h"
#import "MainSearchViewController.h"
#import "DoubleBallViewController.h"
#import "UIColor+expanded.h"
@interface TicketListViewController ()

@end

@implementation TicketListViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.table.separatorStyle=UITableViewCellSeparatorStyleNone;
	// Do any additional setup after loading the view.
//    [self GetWeatherSearch:self.query Location:self.city];

}

#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    //NSArray *list=[[[weatherIndex objectAtIndex:0] objectForKey:@"Properties"] objectForKey:@"Property"];
   
        return self.arrReturn.count;
   
}

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier=@"CellIdentifier";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell==nil){
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;

    }
    NSUInteger row=[indexPath row];
    NSString *str=[[self.arrReturn objectAtIndex:row] objectForKey:@"Title"];
     cell.textLabel.backgroundColor=[UIColor clearColor];
    cell.textLabel.text=str;
       cell.textLabel.font=[UIFont systemFontOfSize:14];
    cell.imageView.image=[UIImage imageNamed:str];
   
    if (indexPath.row%2==1) {
        UIView *vie=[[UIView alloc]init];
        vie.backgroundColor=[UIColor colorWithHexString:@"0xf3f3f3"];
        cell.backgroundView=vie;
    }
    else{
        cell.backgroundColor=[UIColor clearColor];
    }
    return cell;
}



//- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
//    return @"热门彩票近期开奖信息";
//}

//#pragma mark - Get Lottery Ticket Data
//-(void)GetWeatherSearch:(NSString*)Query Location:(NSString*)City{
//    tRequest=tRequest=[[[ScreenAccess alloc]init]ASIGetSearch:Query Start:0 Limit:10];    [tRequest setDelegate:self];
//    [tRequest setUsername:@"lotteryTicket"];
//}
//
//-(void)requestFinished:(ASIHTTPRequest*)request{
//    NSString *response = [request responseString];
//    SBJsonParser * parser = [[SBJsonParser alloc] init];
//    NSMutableDictionary *Result = [parser objectWithString:response];
//    
//    if ([request.username isEqual:@"lotteryTicket"]){
//        BOOL IsSuccess=[[[Result objectForKey:@"Response"]objectForKey:@"status"]integerValue]==200?YES:NO;
//        if (IsSuccess==YES) {
//            NSMutableArray *arrReturn=[[NSMutableArray alloc] init];
//            [arrReturn addObject:[[Result objectForKey:@"Response"] objectForKey:@"Categories"]];
//            for (int i=0; i<arrReturn.count; i++) {
//                NSArray *arr=[[arrReturn objectAtIndex:i] objectForKey:@"Category"];
//                for (int j=0; j<arr.count; j++) {
//                    if([[[arr objectAtIndex:j] objectForKey:@"name"] isEqual:@"lotto"])
//                    {
//                        NSArray *itemReturn=[[NSArray alloc] init];
//                        itemReturn=[[[arr objectAtIndex:j] objectForKey:@"Items"] objectForKey:@"Item"];
//                        for (int k=0; k<itemReturn.count; k++) {
//                            if(ticketList==nil){
//                                ticketList=[[NSMutableArray alloc] init];
//                            }
//                            [ticketList addObject:[itemReturn objectAtIndex:k]];
//                        }
//                    }
//                }
//            }
//        }
//        [self.table reloadData];
//    }
//}
//
//-(void)requestFailed:(ASIHTTPRequest*)request{
//    
//}

//#pragma mark - Table Delegate Methods
//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 60;
//}
- (MainSearchViewController *)menuContainerViewController {
    return (MainSearchViewController *)self.parentViewController;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSUInteger row=[indexPath row];
    //NSString *lotteryName=[[ticketList objectAtIndex:row] objectForKey:@"Title"];
    NSString *lotteryName=[[self.arrReturn objectAtIndex:row] objectForKey:@"href"];
    NSArray *tempStr=[lotteryName componentsSeparatedByString:@"="];
    NSString *queryStr=[tempStr objectAtIndex:1];
    DoubleBallViewController *doubleBallController =[[DoubleBallViewController alloc] init];
    doubleBallController.city=@"上海";
    doubleBallController.query=queryStr;
    doubleBallController.lotteryIndex=row;
    
    [[self menuContainerViewController].navigationController pushViewController:doubleBallController animated:YES];
}
@end
